﻿using Sc.Domain;
using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Sc.Web.Controllers
{
    public class UserController : Controller
    {
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <returns></returns>
        public ActionResult UserLogin()
        {
          //  new UserService().UserLoginForApp("czsjq", "123456", "", 1);
            return View();
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="code">账号</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public int SubUserLogin(string code, string pwd)
        {
            UserService user = new UserService();
            var data = user.UserLoginForPc(code, pwd);
            if (data != null)
            {
                DateTime expiration = DateTime.Now.AddHours(8);
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, data.UserName, DateTime.Now, expiration,
                    false, "{UserId:" + data.UserId + ",UserName:'" + data.UserName + "',OrgzNo:" + data.OrgzNo + "}", FormsAuthentication.FormsCookiePath);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                HttpContext.Response.Cookies.Set(cookie);
                return 1;
            }
            return 0;
        }
        
    }
}